package com.javen.controller;


import com.jfinal.aop.Interceptor;
import com.jfinal.aop.Invocation;
import com.jfinal.core.Controller;
import com.jfinal.render.Render;

public class RenderSwitchInterceptor implements Interceptor {
    @Override
    public void intercept(Invocation ai) {
        Controller c = ai.getController();
        ai.invoke();
        Render render = c.getRender();
        String returnPath = render.getView(); // ctrl中render的字符串
        String viewPath = "";
       
        String agent=c.getRequest().getHeader("User-Agent").toLowerCase();
        if (isMobile(agent)){ //手机
        	viewPath = "wap/";
        }
        render.setView(viewPath+returnPath);
    }
    public boolean isMobile(String agent) {
    	  if(agent.indexOf("windows")>0){
    		  return false;
    	  }else{
    		  return true;
    	  }
    }
  }
  